<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 资产
 */
class Assets extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    /***
     * 用户资产
     * @return void
     */
    public function info()
    {
        $data = [
            'bhd' => [
                'total_amount' => '0.00',
                'frozen_amount' => '0.00',
                'wait_amount' => '0.00',
                'sure_amount' => '0.00',
            ],
        ];
        $this->success(__('获取成功'), $data);
    }

    /***
     * 收益记录
     * @return void
     */
    public function profitList()
    {
        $user = $this->auth->getUser();
        $user_id = $user['id'];
        $list = model('app\common\model\HNTLog')->field("id ,HNT as `amount`, createtime")->order('id desc')->where('user_id', $user_id)->paginate(10);
        if (!$list->isEmpty()) {
            foreach ($list as $item) {
                $item->coin_type = 'HNT';
                $item->coin_type_text = 'HNT';
            }
        }
        $this->success(__('获取成功'), $list);
    }

    /***
     * 消费记录
     * @return void
     */
    public function consumerList()
    {
        $user = $this->auth->getUser();
        $user_id = $user['id'];
        $list = model('app\admin\model\Order')->field("id ,pay_price,state, createtime")->order('id desc')->where('user_id', $user_id)->paginate(10);

        if (!$list->isEmpty()) {
            foreach ($list as $item) {
                $item->coin_type = 'HNT';
                $item->coin_type_text = 'HNT';
            }
        }
        $this->success(__('获取成功'), $list);
    }

    /***
     * 充值记录
     * @return void
     */
    public function rechargeList()
    {
        $user = $this->auth->getUser();
        $user_id = $user['id'];
        $list = model('app\common\model\MoneyLog')->field("id, money, createtime")->order('id desc')->where(['user_id' => $user_id, 'money' => ['>', 0]])->paginate(10);

        if (!$list->isEmpty()) {
            foreach ($list as $item) {
                $item->coin_type = 'HNT';
                $item->coin_type_text = 'HNT';
            }
        }
        $this->success(__('获取成功'), $list);
    }

    /***
     * 提现记录
     * @return void
     */
    public function withdrawList()
    {
        $user = $this->auth->getUser();
        $user_id = $user['id'];
        $list = model('app\admin\model\user\UserWithdrawcoin')->where('user_id', $user_id)->field("id ,coin_type,status,amount, createtime")->order('id desc')->paginate(10);
        $this->success(__('获取成功'), $list);
    }
}